<?php

namespace app\erp\model;

use think\Model;

class UCartdb extends Model
{
    protected $connection = 'database.utec_db';
    protected $name = 'cart';
    protected $pk = 'cart_id';

    public function saveCart($order_no)
    {
        $cartdb = new Cartdb();
        $get_carts = $cartdb->where('order_no', $order_no)->select();
        if ($get_carts) {
            $get_carts = $get_carts->hidden(['cart_id'])->toArray();
            $get_u_carts = $this->where('order_no',$order_no)->column('cart_id');
            if(count($get_u_carts)>0) {
                $this->destroy($get_u_carts);
            }
            foreach ($get_carts as $key=>$val){
                $get_carts[$key]['create_time'] = strtotime($val['create_time']);
            }
            $this->saveAll($get_carts);
        }
        return true;
    }
}